<template>
  <div class="index">
    <header>
      <button @click="toEdit">开始写作</button>
      <router-link to="Login" tag="button">去登录</router-link>
    </header>

    <div class="first">
      首页
      <button @click="toEdit">开始写作</button>
    </div>
    <input type="file" multiple @change="uploadHandler" />
  </div>
</template>

<script>
import { mapState, mapGetters, mapActions } from "vuex";
import { upload } from "@/request/api";
export default {
  name: "Index",
  meta: {
    title: "首页",
    requireAuth: false,
  },
  computed: {
    ...mapState("login", ["isMember"]),
    ...mapGetters("login", ["isLoginedIn"]),
  },
  components: {},
  created() {},
  methods: {
   
    toEdit() {
      if (!this.isLoginedIn) {
        this.toLogin();
      } else {
        console.log(this.isMember);
        if (this.isMember) {
          this.$router.push({
            path: "Edit/Mould",
          });
        } else {
          this.$router.push({
            path: "Edit/Member",
          });
        }
      }
    },
    toLogin() {
      this.$router.push({
        path: "Login",
        query: {
          id: 123,
        },
      });
    },
    uploadHandler(e) {
      console.log(e.target.files);
      let fileList = e.target.files;
      let forms = new FormData();
      for (var i = 0; i < fileList.length; i++) {
        forms.append("fileUrl", fileList[i]);
      }
      upload(forms);
    },
  },
};
</script>
<style lang="scss" scoped>
.index {
  > header {
    height: 60px;
    line-height: 60px;
  }
}
.first {
  width: 100%;
  height: 100px;
  // border: 1px solid red;
  > .child {
    color: #fff;
  }
}
</style>